package com.autumn.jvm.jvm;

import org.openjdk.jol.info.ClassLayout;

/**
 * @author: Autumn
 * @describe:
 * @date: 2022/10/5
 * @modified By:
 */
public class JOLSample {
    public static void main(String[] args) {
        ClassLayout layout = ClassLayout.parseInstance(new Object());
        System.out.println(layout.toPrintable());
        System.out.println("====================");

        ClassLayout layout1 = ClassLayout.parseInstance(new int[]{});
        System.out.println(layout1.toPrintable());
        System.out.println("====================");

        ClassLayout layout2 = ClassLayout.parseInstance(new A());
        System.out.println(layout2.toPrintable());
    }

    //-XX:+UseCompressedOops           默认开启的压缩所有指针
    //-XX:+UseCompressedClassPointers  默认开启的只压缩对象头里的类型指针Klass Pointer
    //Oops:Ordinary Object Pointers
    public static class A {
                        //8B    Mark Word
                        //4B    Klass Pointer   若关闭压缩-XX:-UseCompressedClassPointers或-XX:-UseCompressedOops，则占用8B
        int id;         //4B
        String name;    //4B    若关闭压缩-XX:-UseCompressedOops，则占用8B
        byte b;         //4B
        Object o;       //4B    若关闭压缩-XX:-UseCompressedOops，则占用8B
    }
}
